package com.shanghaionstar.mro;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;

import com.onstar.cn.common.util.PreferencesUtls;
import com.onstar.cn.framework.annotation.FindViewById;
import com.onstar.cn.weight.CustomImageView;
import com.shanghaionstar.R;
import com.shanghaionstar.enumtype.DealerBrandType;
import com.shanghaionstar.utils.ApplicationUtil;
import com.shanghaionstar.utils.FinalConstants;


/**
 * Created by kai zhang on 2015/10/15 18:08.
 * 小O帮助界面
 */
public class MrOHelpFragment extends MrOBaseFragment {
    private View view;
    private MrOActivity mroActivity;
    @FindViewById
    private RelativeLayout rn_mro_xinx, rn_mr_fw, rn_mr_dh, rn_mr_talk, rn_mr_other;
    @FindViewById
    private CustomImageView rn_mr_big;

    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        if (view == null) {
            view = inflater.inflate(R.layout.mro_help, container, false);
            injectView(view);
        } else {
            super.onResumeView(view);
        }
        return view;
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        checkFigureConfig();
    }

    private void checkFigureConfig() {
        String currentFigure = PreferencesUtls.getInstance(mroActivity).getString(FinalConstants.MroConstants.MRO_FIGURE_KEY);
        if ("".equals(currentFigure) || FinalConstants.MroConstants.MRO_FIGURE_DEFAULT.equals(currentFigure)) {
            rn_mr_big.setImageResource(R.drawable.mro_default_normal);
        } else if (FinalConstants.MroConstants.MRO_FIGURE_BRAND.equals(currentFigure)) {
            DealerBrandType myBrand = DealerBrandType.getDealerBrandTypeByDesc(ApplicationUtil.getInstance().getCarInfo());
            switch (myBrand) {
                case CHEVROLET:
                    rn_mr_big.setImageResource(R.drawable.mro_chevrolet_normal);
                    break;
                case BUICK:
                    rn_mr_big.setImageResource(R.drawable.mro_buick_normal);
                    break;
                case CADILLAC:
                    rn_mr_big.setImageResource(R.drawable.mro_cadillac_normal);
                    break;
            }
        } else if (FinalConstants.MroConstants.MRO_FIGURE_WTK.equals(currentFigure)) {
            rn_mr_big.setImageResource(R.drawable.mro_wtk_normal);
        }
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        mroActivity = (MrOActivity) activity;
    }

    @Override
    public void onStart() {
        super.onStart();
        mroActivity.showBottomRightBtn(false);
        mroActivity.showBottomMrO(false);
    }

    @Override
    public boolean onBackPressed() {
        mroActivity.showBottomRightBtn(true);
        return false;
    }

    /**
     * 初始化
     */
    @com.onstar.cn.framework.annotation.OnClick({R.id.rn_mro_xinx, R.id.rn_mr_fw, R.id.rn_mr_dh,
            R.id.rn_mr_dh, R.id.rn_mr_talk, R.id.rn_mr_other, R.id.rn_mr_vehicle_condition,
            R.id.rn_mr_chat, R.id.rn_mr_story, R.id.rn_mr_joke})
    public void OnClick(View v) {
        int layoutid = 0;
        switch (v.getId()) {
            case R.id.rn_mro_xinx:
                layoutid = R.layout.mro_help_single1;
                break;
            case R.id.rn_mr_fw:
                layoutid = R.layout.mro_help_single2;
                break;
//            case R.id.rn_mr_passwrod:
//                layoutid = R.layout.mro_help_single3;
//                break;
            case R.id.rn_mr_dh:
                layoutid = R.layout.mro_help_single4;
                break;
            case R.id.rn_mr_talk:
                layoutid = R.layout.mro_help_single5;
                break;
            case R.id.rn_mr_other:
                layoutid = R.layout.mro_help_single6;
                break;
            case R.id.rn_mr_vehicle_condition:
                layoutid = R.layout.mro_help_vehicle_condition;
                break;
            case R.id.rn_mr_chat:
                layoutid = R.layout.mro_help_chat;
                break;
            case R.id.rn_mr_story:
                layoutid = R.layout.mro_help_story;
                break;
            case R.id.rn_mr_joke:
                layoutid = R.layout.mro_help_joke;
                break;

        }
        Fragment fragment = MrOHelpTemplateFragment.newInstance(layoutid);
        mroActivity.changeFragment(mroActivity.fragmentManager, fragment, MrOHelpTemplateFragment.class, true);
    }
}
